package com.hyz.login.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hyz.login.mapper.PharmacyMapper;
import com.hyz.login.model.Cashier;
import com.hyz.login.mapper.CashierMapper;
import com.hyz.login.model.Pharmacy;
import com.hyz.login.service.CashierService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zwq
 * @since 2022-11-22
 */
@Service
public class CashierServiceImpl
        extends ServiceImpl<CashierMapper, Cashier> implements CashierService {
    

    @Autowired
    private CashierMapper cashierMapper;
    @Autowired
    private PharmacyMapper pharmacyMapper;

    @Override
    public IPage<Cashier> findByReportId(Integer reportId,Integer page,Integer limit) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        wrapper.eq("state",0);
        Page<Cashier> cashierPage = new Page<Cashier>(page,limit);
        IPage<Cashier> iPage = cashierMapper.selectPage(cashierPage,wrapper);

        return iPage;
    }


    @Override
    public IPage<Cashier> findProjectByReportId(Integer reportId,Integer page,Integer limit) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        wrapper.eq("state",1);
        Page<Cashier> cashierPage = new Page<Cashier>(page,limit);
        IPage<Cashier> iPage = cashierMapper.selectPage(cashierPage,wrapper);

        return iPage;
    }

    @Override
    public Integer findCountByIdAndName(Integer reportId,String mename) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        wrapper.eq("durgname",mename);
        return cashierMapper.selectCount(wrapper);
    }

    @Override
    public Integer addCashier(Cashier cashier) {
        return cashierMapper.insert(cashier);
    }

    @Override
    public Integer updCashier(Cashier cashier) {
        return cashierMapper.updCashier(cashier);
    }

    @Override
    public Integer delById(Integer cashier) {
        return cashierMapper.deleteById(cashier);
    }

    @Override
    public Integer findCountCashierFei(Integer reportId) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        wrapper.eq("state",2);
        wrapper.eq("fei",0);
        return cashierMapper.selectCount(wrapper);
    }

    @Override
    public Integer findCountCashierProject(Integer reportId) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        wrapper.eq("state",1);
        wrapper.ne("mstate",1);
        return cashierMapper.selectCount(wrapper);
    }

    @Override
    public  Integer findById(Integer reportId) {
        return cashierMapper.findById(reportId);
    }

    @Override
    public Integer modifyFeiById(Integer reportId) {
        return cashierMapper.modifyFeiById(reportId);
    }

    @Override
    public IPage<Cashier> findProjectList(Integer reportId,Integer page,Integer limit) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        wrapper.eq("state",1);
        wrapper.eq("durgname","ct");
        Page<Cashier> cashierPage = new Page<Cashier>(page,limit);
        IPage<Cashier> iPage = cashierMapper.selectPage(cashierPage,wrapper);
        return iPage;
    }

    @Override
    public Integer modifyProjectByCashier(Integer reid, String bing, Integer cashier) {
        Cashier cash = new Cashier();
        cash.setCashier(cashier);
        cash.setJie(bing);
        cash.setReportId(reid);
        return cashierMapper.updateById(cash);
    }

    @Override
    public IPage<Cashier> findCashierByReportId(Integer reportId,Integer page,Integer limit) {
        QueryWrapper<Cashier> wrapper = new QueryWrapper<Cashier>();
        wrapper.eq("reportId",reportId);
        Page<Cashier> cashierPage = new Page<Cashier>(page,limit);
        IPage<Cashier> iPage = cashierMapper.selectPage(cashierPage,wrapper);
        return iPage;
    }

    @Override
    public Integer findSumByReportId(Integer reportId) {
        return cashierMapper.findSumByReportId(reportId);
    }
}
